
import actions from '../action/message';
import CONSTANT from '../constant/message';

const app48openIdNum = 0;
const customerMsgList = [];
const subscribeMsgList = [];
const templateMsgList = [];
const customerPage = {
  page: 0,
  size: 20,
  totalElement: 0,
};

const subscribePage = {
  page: 0,
  size: 20,
  totalElement: 0,
};

const templatePage = {
  page: 0,
  size: 20,
  totalElement: 0,
};

const customerMsg = {};
const subscribeMsg = {};

export default {
  actions,
  state: {
    customerMsgList,
    subscribeMsgList,
    templateMsgList,
    customerPage,
    subscribePage,
    templatePage,
    app48openIdNum,
    customerMsg,
    subscribeMsg,
  },
  mutations: {
    [CONSTANT.MESSAGE_GET_CUSTOMER_LIST_SUCCESS](state, { page, publicPushesResponse }) {
      state.customerMsgList = publicPushesResponse;
      state.customerPage = {
        ...state.customerPage,
        page: page.currentPage,
        size: page.pageSize,
        totalElement: page.totalElement,
      };
    },
    [CONSTANT.MESSAGE_GET_CUSTOMER_LIST_ERROR](state) {
      state.customerMsgList = [];
      state.customerPage = customerPage;
    },
    [CONSTANT.MESSAGE_GET_TEMPLATE_LIST_SUCCESS](state, { page, templatePushesResponse }) {
      state.templateMsgList = templatePushesResponse;
      state.templatePage = {
        ...state.templatePage,
        page: page.currentPage,
        size: page.pageSize,
        totalElement: page.totalElement,
      };
    },
    [CONSTANT.MESSAGE_GET_TEMPLATE_LIST_ERROR](state) {
      state.templateMsgList = [];
      state.templatePage = templatePage;
    },
    [CONSTANT.MESSAGE_ADD_CUSTOMER_SUCCESS]() {},
    [CONSTANT.MESSAGE_ADD_CUSTOMER_ERROR]() {},
    [CONSTANT.MESSAGE_ADD_TEMPLATE_SUCCESS]() {},
    [CONSTANT.MESSAGE_ADD_TEMPLATE_ERROR]() {},
    [CONSTANT.MESSAGE_GET_SUBSCRIBE_LIST_SUCCESS](state, { page, pushScriptResponses }) {
      state.subscribeMsgList = pushScriptResponses;
      state.subscribePage = {
        ...state.subscribePage,
        page: page.currentPage,
        size: page.pageSize,
        totalElement: page.totalElement,
      };
    },
    [CONSTANT.MESSAGE_GET_SUBSCRIBE_LIST_ERROR](state) {
      state.subscribeMsgList = [];
      state.subscribePage = subscribePage;
    },

    [CONSTANT.MESSAGE_PREVIEW_SUCCESS]() {},
    [CONSTANT.MESSAGE_UPLOAD_MPNEWS_SUCCESS]() {},
    [CONSTANT.MESSAGE_UPLOAD_MPNEWS_ERROR]() {},
    [CONSTANT.MESSAGE_UPDATE_TEMPLATE_SUCCESS]() {},
    [CONSTANT.MESSAGE_UPDATE_TEMPLATE_ERROR]() {},
    [CONSTANT.MESSAGE_GET_48OPENID_SUCCESS](state, total) {
      state.app48openIdNum = total;
    },
    [CONSTANT.MESSAGE_GET_48OPENID_ERROR](state) {
      state.app48openIdNum = 0;
    },
    [CONSTANT.MESSAGE_GET_CUSTOMER_SUCCESS](state, data) {
      state.customerMsg = data;
    },
    [CONSTANT.MESSAGE_GET_CUSTOMER_ERROR](state) {
      state.customerMsg = {};
    },
    [CONSTANT.MESSAGE_GET_SUBSCRIBE_SUCCESS](state, data) {
      state.subscribeMsg = data;
    },
    [CONSTANT.MESSAGE_GET_SUBSCRIBE_ERROR](state) {
      state.subscribeMsg = {};
    },
  },
  getters: {
    [CONSTANT.MESSAGE_GETTER_LIST](state) {
      return state.MESSAGEList;
    },
  },
};
